/***********************************************************
 * templates                   GCW 02/03/94
 * window_handle = templates(template_file, window_name);
 * template_file is template file
 * window_name is a vector of window names
 * window_handle is the corresponding vector of handles
 ***********************************************************/

#ifndef _wimp_templates
#define _wimp_templates 1
#endif

templates(template_file, window_name)
{
 local r, handle, n, i, padded;
 handle = newvector(n = sizeof(window_name));
 (r = newvector(8))[1] = template_file+0;
 swi("Wimp_OpenTemplate",r);
 for(i=0;i<n;i++)
 {
  r[1] = r[2] = r[3] = 0;
  r[4] = -1;
  r[5] = padded = pad(window_name[i],12,0);
  swi("Wimp_LoadTemplate",r);
  r[1] = newstring(r[1]);
  r[2] = newstring(r[2]);
  r[3] = @(r[2])+sizeof(r[2]);
  r[5] = padded;
  r[6] = 0;
  swi("Wimp_LoadTemplate",r);
  swi("Wimp_CreateWindow",r);
  handle[i] = r[0];
 }
 swi("Wimp_CloseTemplate",r);
 return(handle);
}

/* pad out s to length n with trailing character c's  */
pad(s,n,c)
{
 local len;
 while (sizeof(s)<n)
    s += c;
 return (s);
}
